home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
mymenv-notify 2.0
/
myAEvents.cc
< prev
next >
Wrap
Text File
|
1996-06-04
|
5KB
|
146 lines
/*
************************************************************************
* Handling of Mandatory Apple Events
* OpenApplication, {Open|Print}Document, Quit
*/
#include "mymenv.h"
#include "myAEvents.h"
#include <string.h>
// It is this handler that is called by AEProcessAppleEvent
// Reply noErr if the event is handled successfully.
// ot Eventnothandled it's beyond us
pascal OSErr AppleEventGenericHandler::zero_level_handler
(AppleEvent *_theAppleEvent, AppleEvent *_reply, long handlerRefcon)
{
assert( handlerRefcon != 0 );
AppleEventGenericHandler& handler = *(AppleEventGenericHandler *)handlerRefcon;
assert( handler.signature == Signature_value );
handler.theAppleEvent = _theAppleEvent;
handler.reply = _reply;
return handler();
}
// Install the event handler
// Should've checked that no other event handler wasn't
// installed for that event using
// AEGetEventHandler()
// We pass the ptr to the object as a refcon
AppleEventGenericHandler::AppleEventGenericHandler(const AEEventID _event_id)
: signature(Signature_value), event_class(kCoreEventClass),
event_id(_event_id)
{
zero_level_handler_descr = NewAEEventHandlerProc(zero_level_handler);
do_well( AEInstallEventHandler(event_class,event_id,zero_level_handler_descr,
(long)this, FALSE) );
}
// Uninstall the event handler
AppleEventGenericHandler::~AppleEventGenericHandler(void)
{
do_well( AERemoveEventHandler(event_class,event_id,zero_level_handler_descr,FALSE) );
}
// Check to make sure we got all required params
Boolean AppleEventGenericHandler::got_all_params(void)
{
DescType typeCode; // we don't use them, actually
Size actualSize;
OSErr err = AEGetAttributePtr(theAppleEvent, keyMissedKeywordAttr,
typeWildCard, &typeCode, 0, 0, &actualSize);
if( err == errAEDescNotFound ) // we got all the required params: all is ok
return TRUE;
else if( err == noErr )
return FALSE;
else
do_well( err );
return FALSE;
}
// Get Descriptor of a list as a direct param
void AppleEventGenericHandler::get_direct_list(AEDescList& list_desc)
{
do_well( AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &list_desc) );
}
// Get a full path from an alias record
// Returns a pointer to a static string
// Note, alias has to be a full alias
// (minimal alias doesn't have directories record)
const char * get_full_path(AliasHandle alias_handle)
{
static char path[700]; // Full path to return
Str63 buffer;
// Write a volume name at the beginning of
// the path
do_well( GetAliasInfo(alias_handle,asiVolumeName,buffer) );
memcpy(path,(char *)buffer+1,buffer[0]);
char * first_col_pos = path + buffer[0];
*first_col_pos = ':'; // colon after the volume name
char * after_ldir_pos = first_col_pos+1;
// Put directory names from the parent upwards
// In the string
// Volume_name:Dir3:Dir2:Dir1:
// first_col_pos points to the first : after
// the volume name, after_ldir_pos points
// after the last column. The new directory
// retrieved from the alias record is wedged
// between the volume name and after_vname_pos
for(register int dir_level=1;;dir_level++)
{
do_well( GetAliasInfo(alias_handle,dir_level,buffer) );
if( buffer[0] == 0 )
break; // no more (grand...dad) directories
// Move [after_vname_pos,after_ldir_pos)
// chunk forward to make room for this
// (grand)parent directory
char * p = after_ldir_pos;
char * q = after_ldir_pos += buffer[0]+1; // reserve space for :
assert( after_ldir_pos < path + sizeof(path) );
while( p > first_col_pos )
*--q = *--p;
p = (char *)buffer+1+buffer[0]; // End of the (grand)parent dir name
while( q > first_col_pos+1 )
*--q = *--p;
}
// Get the file name itself and append it to the
// end
do_well( GetAliasInfo(alias_handle,asiAliasName,buffer) );
assert( after_ldir_pos+buffer[0]+1 < path + sizeof(path) );
memcpy(after_ldir_pos,(char *)buffer+1,buffer[0]);
after_ldir_pos[buffer[0]] = '\0'; // Properly terminate the string
return path;
}
#if 0
// This is the real handler
template <class DocHandler>
virtual OSErr AppleEventOpenDoc<DocHandler>::operator() (void)
{
get_direct_list(desc_opened_doc);
assert( got_all_params() );
do_well( AECountItems(&desc_opened_doc, &no_opened_doc) );
OSErr err_sofar = noErr;
DocHandler doc_handler(no_opened_doc);
int want_handle = 1;
assert( want_handle <= no_opened_doc );
for(register int index=1; err_sofar == noErr && index <= want_handle; index++)
{
Size actual_size;
AEKeyword keyword;
DescType type_code;
do_well( AEGetNthPtr(&desc_opened_doc, index, typeFSS, &keyword, &type_code,
(Ptr)&file_spec, sizeof(file_spec), &actual_size) );
if( !doc_handler(file_spec) )
err_sofar = errAEEventNotHandled;
}
do_well( AEDisposeDesc(&desc_opened_doc) );
return err_sofar;
}
#endif